<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    @include('public.h5_head')
    <title>完善商品信息</title>
    <link rel="stylesheet" type="text/css" href="/css/prefect/common.css"/>
    <link rel="stylesheet" type="text/css" href="/css/prefect/information.css"/>
    <link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_o5vjtg2qn5sfko6r.css"/>
</head>
<script src="/js/rem.js"></script>
{{--
<script src="/js/iscroll.js"></script>
--}}
<script src="/js/jquery-3.2.0.min.js"></script>
<style type="text/css">
    .information_size{
        cursor: pointer;
    }

</style>
<body>
<div id="box_information">
    <header>
        <div class="iconfont icon-zuojiantou arrows" onclick="javascript:history.go(-1);"></div>
        <div class="header_c">完善商品信息</div>
        {{-- <input id="save_information" class="save_information"  onclick="document.getElementById('#prefect_form').submit();" value="保存" />--}}
        <input id="save_information" class="save_information"  value="保存" />
    </header>
    <div class="wrap">
        <div class="main_information">
            <form name="prefect_form" class="prefect_form" id="prefect_form" method="post" action=""></form>
            <div class="add_success" style="display: block;">添加信息</div>
        </div>
    </div>
    <footer style="display:block;">
        <div class="footer_l">
            <div><input type="hidden" id="checkAll"> <i class="iconfont icon-weixuanzhongyuanquan arrows ic"></i>&nbsp;全选</div>
        </div>
        <div class="footer_r">
            <input type="button" value="" class="del_inp footer_btn" />
            <input type="button" value="删除" class="put_inp footer_btn" />
        </div>
    </footer>
    <div class="save_success" style="display: none;">保存成功</div>
</div>
<meta name="_token" id="token" content="{{ csrf_token() }}">
</body>
{{--
<script src="/js/information.js"></script>
--}}{{--{{$_GET['produc_id']}}--}}
<script>
    $(".add_success").click(function(){
        var divs =  "<div class='information'>" +
                "<div class='informationDiv'><div class='iconfont icon-yuanquanxuanzhong' style='display: none'></div>"+
                "<div class='iconfont icon-weixuanzhongyuanquan allicon' style='display: block;'><input type='hidden' class='size'  name='single' value='1'></div></div>"+
                "<div class='information_fixation'><div class='information_top'><p class='information_p'>款式：</p>"+
                "<input type='text' maxlength='4' class='information_txt' name='fashion' ><input type='hidden' name='produc_id' value='{{$_GET['produc_id']}}'><input type='hidden' name='goods_id' value=''>"+
                "</div><div class='information_center'><p class='information_center_size'>尺码：</p>"+
                "<ul><li class='information_size'>6</li><li class='information_size'>7</li><li class='information_size'>8</li><li class='information_size'>9</li>"+
                "<li class='information_size'>10</li><li class='information_size'>11</li><li class='information_size'>12</li>"+
                "<li class='information_size'>13</li><li class='information_size'>14</li><li class='information_size'>15</li>"+
                "</ul></div></div><div class='information_auto' style='display: none;'></div></div>";
        $('.prefect_form').prepend(divs);
        produc_id  = $("input[name=produc_id]").val();
        $.ajax({
            type: "POST",
            dataType: 'json',
            url: "/goods/add_goodsinfo",
            async:true ,
            //data: {produc_id : produc_id ,produc_val : produc_val},
            data: {produc_id :  produc_id  } ,
            headers: {
                'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
            },
            success: function (data) {
                //  $("input[name=goods_id]").val(data);
                //alert(data.produc_id);
            },
            error: function (XMLHttpRequest, textStatus) {
                console.log(XMLHttpRequest.status);
                console.log(XMLHttpRequest.readyState);
                console.log(textStatus);
            }
        });
    });
    $("#save_information").click(function(){
        //produc_id = '84';
        produc_id  = $("input[name=produc_id]").val();
        produc_val =  $("form").serialize();
        $.ajax({
            type: "POST",
            dataType: 'json',
            url: "/goods/save_goods_prefect",
            async:true  ,
            //data: {produc_id : produc_id ,produc_val : produc_val},
            data: produc_val ,
            headers: {
                'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
            },
            success: function (data) {
                //window.location.href = '/goods/prefect';
            },
            error: function (XMLHttpRequest, textStatus) {
                console.log(XMLHttpRequest.status);
                console.log(XMLHttpRequest.readyState);
                console.log(textStatus);
            }
        });
    });
    function delgoodsinfo(){
        var ids = '';
        $(document).on('click', '.footer_l', function () {
            $(".ic").css('background-color', '#000000');
            $(".ic").css('border-radius', '20px');
            $('.size').each(function (i) {
                $(".allicon").css('background-color', '#000000');
                ids += ',' + $(this).val();
            });
            if (ids.length == 0) {
                alert('请选择要删除的选项');
            } else {
                if (confirm("确定删除?")) {
                    $.ajax({
                        type: "POST",
                        dataType: 'json',
                        url: "/goods/del",
                        data: {ids: ids},
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                        },
                        success: function (data) {
                            var data_json = eval("(" + data + ")");
                            if (data_json == false) {
                                return false;
                            }
                            //window.location.href='/goods';
                        },
                        error: function (XMLHttpRequest, textStatus) {
                            console.log(XMLHttpRequest.status);
                            console.log(XMLHttpRequest.readyState);
                            console.log(textStatus);
                        }

                    });
                }
            }
        });
    }
</script>
<script>
    $(document).ready(function() {
        var sizeinfo = "<div class='information_bottom'>"+
                "<input type='text' readonly='readonly' class='infor_mo' /><p class='information_sum infor_sp'>数量：<input type='text' name='stock' id='stock' placeholder='件' maxlength='5' class='infor_txt' /></p>"+
                "<p class='information_price infor_sp'>价格：<input type='text' name='price' id='price' placeholder='元' maxlength='6' class='infor_txt' /></p></div>";
        fashion = $("input[name=produc_id]").val();
        color = $("input[name=fashion]").val();
        price = $("input[name=price]").val();
        stock = $("input[name=stock]").val();
        $(document).on('click','.information_size',function(){
            $(this).each(function(i) {
                this_li_v = $(this).html();
                produc_id  = $("input[name=produc_id]").val();
                //  produc_id = $("input[name=produc_id]").val();
               // $(this).find('icon-weixuanzhongyuanquan').css('background', 'black');
                $(this).css('border', '1px solid black');
                $.ajax({
                    type: "POST",
                    dataType: 'json',
                    url: "/goods/validate_size",
                    async: true,
                    data: {size: this_li_v, produc_id: produc_id},
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                    },
                    success: function (data) {
                        //window.location.href = '/goods/prefect';
                        if (data.status == 0) {
                            $('.information_auto').css('display', 'block');
                            $('.information_auto').prepend(sizeinfo);
                            $.ajax({
                                type: "POST",
                                dataType: 'json',
                                url: "/goods/add_size",
                                async:true ,
                                data: {produc_id : produc_id ,produc_val : this_li_v },
                                headers: {
                                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                                },
                                success: function (data) {
                                    //window.location.href = '/goods/prefect';
                                    if (data.status == 0) {
                                        $('.information_auto').css('display', 'block');
                                        $('.information_auto').prepend(sizeinfo);
                                        $(this).find('icon-weixuanzhongyuanquan').css('background', 'black');
                                        $(this).css('border', '1px solid black');
                                    }else if (data.status == 1){
                                        alert('已经添加过相应商品尺码');
                                        return false ;
                                    }
                                },
                                error: function (XMLHttpRequest, textStatus) {
                                    console.log(XMLHttpRequest.status);
                                    console.log(XMLHttpRequest.readyState);
                                    console.log(textStatus);
                                }
                            });


                        } else if (data.status == 1) {
                            alert('已经添加过相应商品尺码');
                            return false;
                        }
                    },
                    error: function (XMLHttpRequest, textStatus) {
                        console.log(XMLHttpRequest.status);
                        console.log(XMLHttpRequest.readyState);
                        console.log(textStatus);
                    }
                });
            });
        });

        $(document).on('change','.information_txt',function(){
            produc_id  = $("input[name=produc_id]").val();
            color = $("input[name=fashion]").val();
            $.ajax({
                type: "POST",
                dataType: 'json',
                url: "/goods/update_color",
                async:true ,
                data: {color:color, produc_id: produc_id },
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                },
                success: function (data) {

                }
            });

        });
        $(document).on('change','#price',function(){
            price = $("input[name=price]").val();
            produc_id  = $("input[name=produc_id]").val();
            $.ajax({
                type: "POST",
                dataType: 'json',
                url: "/goods/add_price",
                async:true ,
                data: {price:price, produc_id: produc_id },
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                },
                success: function (data) {

                }
            });

        });

        $(document).on('change','#stock',function(){
            stock = $("input[name=stock]").val();
            produc_id  = $("input[name=produc_id]").val();
            $.ajax({
                type: "POST",
                dataType: 'json',
                url: "/goods/add_stock",
                async:true ,
                data: {stock:stock, produc_id: produc_id },
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                },
                success: function (data) {

                }
            });

        });


    });
</script>
</html>